//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.sinosoft.hydra.um.domain.permission;

import cn.com.sinux.spring.commons.TreeNode;
import cn.com.sinux.spring.utils.ValidatorUtils;;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Entity
@DynamicInsert(true)
@DynamicUpdate(true)
@Table(
        name = "UM_SYS_ORGANIZATION"
)
public class SysOrganization extends IdEntity implements TreeNode<SysOrganization> {
    private static final long serialVersionUID = 4229500544150442533L;
    private String orgName;
    private String parentId;
    private String orgCode;
    private SysOrganization sysOrganization;
    private Integer available;
    private Integer orderNo;
    private Date createTime;
    private String orgJobs;
    private List<SysOrganization> children;
    private List<SysOrganizationUser> sysOrganizationUsers;
    private TDirectory depBelong;


    @OneToMany
    @JoinColumn(name = "ORGANIZATION_ID")
    public List<SysOrganizationUser> getSysOrganizationUsers() {
        return sysOrganizationUsers;
    }

    public void setSysOrganizationUsers(List<SysOrganizationUser> sysOrganizationUsers) {
        this.sysOrganizationUsers = sysOrganizationUsers;
    }

    @Transient
    public List<SysUserMember> getUserMembers(){
        List<SysUserMember> sysUserMembers = new ArrayList<SysUserMember>();
        if(ValidatorUtils.isArrayNotEmpty(sysOrganizationUsers)){
            for(SysOrganizationUser sysOrganizationUser : sysOrganizationUsers){
                sysUserMembers.add(sysOrganizationUser.getSysUserMember());
            }
        }
        return sysUserMembers;
    }

    @Transient
    public List<? extends TreeNode> getChildren() {
        return children;
    }

    public void setChildren(List<SysOrganization> children) {
        this.children = children;
    }


    public SysOrganization() {
    }

    public SysOrganization(String id) {
        this.id = id;
    }

    @Column(
            name = "ORG_CODE"
    )
    public String getOrgCode() {
        return orgCode;
    }

    public void setOrgCode(String orgCode) {
        this.orgCode = orgCode;
    }

    @Column(
            name = "ORG_NAME"
    )
    public String getOrgName() {
        return this.orgName;
    }

    public void setOrgName(String orgName) {
        this.orgName = orgName;
    }

    @Column(
            name = "PARENT_ID"
    )
    public String getParentId() {
        return this.parentId;
    }

    public void setParentId(String parentId) {
        this.parentId = parentId;
    }

    @Column(
            name = "AVAILABLE"
    )
    public Integer getAvailable() {
        return this.available;
    }

    public void setAvailable(Integer available) {
        this.available = available;
    }


    @Column(
            name = "ORDER_NO"
    )
    public Integer getOrderNo() {
        return this.orderNo;
    }

    public void setOrderNo(Integer orderNo) {
        this.orderNo = orderNo;
    }

    @ManyToOne(
            fetch = FetchType.LAZY
    )
    @JoinColumn(
            name = "PARENT_ID",
            nullable = true,
            updatable = false,
            insertable = false
    )
    @NotFound(
            action = NotFoundAction.IGNORE
    )

    public SysOrganization getSysOrganization() {
        return this.sysOrganization;
    }

    public void setSysOrganization(SysOrganization sysOrganization) {
        this.sysOrganization = sysOrganization;
    }

    @Column(
            name = "CREATE_TIME",
            columnDefinition = "DATETIME DEFAULT CURRENT_TIMESTAMP"
    )
    public Date getCreateTime() {
        return this.createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    @Column(
            name = "ORG_JOBS"
    )
    public String getOrgJobs() {
        return orgJobs;
    }

    public void setOrgJobs(String orgJobs) {
        this.orgJobs = orgJobs;
    }

    @OneToOne
    @JoinColumn(name="DEP_BELONG")
    @NotFound(action = NotFoundAction.IGNORE)
    public TDirectory getDepBelong() {
        return depBelong;
    }

    public void setDepBelong(TDirectory depBelong) {
        this.depBelong = depBelong;
    }
}
